// pages/item/item.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    records: {},
    loadingHidden:'false',
    hide:'true',
    isDown: false,
    percent: 100,
  },
  dashang:function(){
    wx.navigateToMiniProgram({
      appId: 'wx18a2ac992306a5a4',
      path: 'pages/apps/largess/detail',
      extraData: {
        foo: 'bar'
      },
      envVersion: 'develop',
      success(res) {
        // 打开成功
      }
    })
  },
  read: function (event){
    var bookId = event.currentTarget.dataset.id;
    var bookName = event.currentTarget.dataset.keyword;
    var openid = wx.getStorageSync('openid');
    var that=this;
    wx.request({
      url: app.globalData.serverIp + 'records/check.json',
      data: {
        'bookId': bookId,
        'openId': openid
      },
      method: "POST",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        var index2 = res.data.data.sendData.index2;
        wx.navigateTo({
          url: '../read/read?bookId=' + bookId + '&bookName=' + bookName + '&index=' + index2,
        })
        wx.setNavigationBarTitle({
          title: bookName
        })
      }
    })

    
  },
  copyBtn: function (event) {
    var that = this;
    var downLoadUrl = app.globalData.serverIp +"tx.html?fileName="+event.currentTarget.dataset.name;
    console.log(downLoadUrl)
    wx.setClipboardData({
      //准备复制的数据
      data: downLoadUrl,
      success: function (res) {
        wx.showToast({
          title: '复制成功',
          icon: 'success',
          duration: 1000
        })
        wx.showModal({
          title: '复制成功',
          content: '关注公众号 Yyyybook反馈建议   打开浏览器进行下载',
          showCancel: false ,
          confirmColor:'#000000' ,
          success(res) {
          }
        })
      }
    });

  },
  download: function (event){
    var that = this;
    // that.setData({
    //   loadingHidden: false,
    //   isDown: true,
    //   percent: 100,
    //   hide: false
    // })
    // var downLoadUrl = event.currentTarget.dataset.name;
    // wx.downloadFile({
    //   url: 'http://139.155.116.73:8080/吞噬星空.txt',
    //    success: function (res) {
    //      that.setData({
    //        loadingHidden: true
    //      })
    //     var filePath = res.tempFilePath;
    //      console.log(res);                     
    //      wx.openDocument({  
    //     filePath: filePath, 
    //     success: function (res) {   
    //     console.log('打开文档成功')         
    //    }        
    //    })     
    //     }    
    //     })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
   var that=this;
    that.setData({
      id: options.id                           
    })
    wx.request({
      url: app.globalData.serverIp + 'book/getBookById.json',
      data: {
        'bookId': that.data.id
      },
      method: "POST",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        that.setData({
          records: res.data.data.sendData
        })
        wx.setNavigationBarTitle({
          title: res.data.data.sendData.bookName
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})